package com.basic.hellorabbit.config;

import org.springframework.context.annotation.Configuration;

/**
* @Description:    SpringSecurity配置类
* @Author:         Joe
* @CreateDate:     2020/3/22 12:36
*/
//@Configuration
//@EnableWebSecurity
/*public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private SecurityUserService securityUserService;

    //@Override
    protected void configure(HttpSecurity http) throws Exception {
        //定义http访问规则
        http.authorizeRequests()
                .antMatchers("/").permitAll() //主路径允许访问不被拦截：@RequestMapping(value = "/",method = RequestMethod.GET)
                .anyRequest().authenticated()             //其它的请求必须要验证，会被拦截： @RequestMapping(value = "/testSecurity",method = RequestMethod.GET)
                .and()
                .logout().permitAll()
                .and()
                .formLogin();
        http.csrf().disable();  //关闭csrf
        //super.configure(http);
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        //放行静态资源
        web.ignoring().antMatchers("/js/**","/css/**","/images/**");
        //super.configure(web);
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        //1.只进行登录功能即可（可支持多人）
        //auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()).withUser("root1").password(passwordEncoder().encode("123456")).roles("ADMIN");
        //auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()).withUser("root2").password(passwordEncoder().encode("123456")).roles("ADMIN");

        //2.指定角色去访问
        //auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()).withUser("user1").password(passwordEncoder().encode("123456")).roles("USER");

        //auth可以自由指定用户
        auth.userDetailsService(securityUserService);
        //super.configure(auth);
    }

    *//**
     * 密码处理（Spring security5中新增加了加密方式，并把原有的spring security的密码存储格式替换）
     * @return
     *//*
    @Bean
    public static PasswordEncoder passwordEncoder(){
        return NoOpPasswordEncoder.getInstance();
    }
}*/
